<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><{$lang.quanlity}>单<{$lang.operation}></title>
<link href="/css/backstage.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/backstage.js"></script>
<link href="/css/blitzer/jquery-ui.css" rel="stylesheet" type="text/css" /> 
<link href="/css/pagination.css" rel="stylesheet" type="text/css" /> 
<link href="/css/product/quality.css" rel="stylesheet" type="text/css"/> 
<script type="text/javascript" src="/js/jquery-ui.js"></script>

<script src="/js/jquery.pagination.js" type="text/javascript"></script> 
<script src="/js/jquery.loading.js" type="text/javascript"></script> 
<script src="/js/cff.pagination.js" type="text/javascript"></script> 
<script src="/js/cff.iframe.dialog.js" type="text/javascript"></script> 
<script src="/js/cff.autocomplete.js" type="text/javascript"></script> 
<script type="text/javascript" src="/js/product/quality/qc-select-shelf.js"></script>
<script type="text/javascript" src="/js/jquery.fancybox.js"></script>
<link rel="stylesheet" type="text/css" href="/css/jquery.fancybox.css" media="screen" />
<link rel="stylesheet" type="text/css" href="/css/jquery.fancybox-thumbs.css" />
<script type="text/javascript" src="/js/jquery.fancybox-thumbs.js"></script>
<script type="text/javascript" >
<{include file='product/quality/js/qc.js'}>
</script>
<script type="text/javascript">
	
	$(function(){
		$('.fancybox-thumbs').fancybox({
			prevEffect	: 'none',
			nextEffect	: 'none',
			helpers	: {
				title	: {
					type: 'outside'
				},
				overlay	: {
					opacity : 0.8,
					css : {
						'background-color' : '#000'
					}
				},
				thumbs	: {
					width	: 50,
					height	: 50
				}
			}
		});	
	})
</script>
<style>
#content{
	background: none repeat scroll 0 0 white;
    height: 900px;
    margin-left: auto;
    margin-right: auto;
    position: relative;
    text-align: center;
    width: 840px;
	padding:20px;
	font-size:13px;
}
table { 
	border-collapse: collapse; 
	border: none; 
	width: 100%; 
} 
td { 
	border: solid #000000 1px; 
	height:27px;
} 
.button{
	border: 1px solid #318DAC;
    border-radius: 3px 3px 3px 3px;
    color: #318DAC;
    font-weight: lighter;
    margin: auto 5px;
    padding: 2px 5px;
    vertical-align: middle;
	background:#F1F6F9;
}
.fontBold{
	font-weight:bold;
}
</style>
<script>
$(function(){
	$("#tipDialog").dialog({
		autoOpen:false,
		modal:true,
		width:300,
		show:"slide",
		buttons:{
			"Close":function(){
				$(this).dialog("close");
			}
		}
	});
	
	$('.stkinfo').click(function(){
		 window.open("http://121.15.134.94:8686/product/cffprod/proddetail/prodId/"+$('#<{$lang.sku}>').val());
	});
	
	$('.qcConfirm').click(function(){
		//<{$lang.data}>检验
		var qqproblemNullNaN = unpassCheck = qqproblemNum = unqcnumMaxqco_real_quantity=qqproblemCode=qqNullNote =qqpassNullNaNQR= qqpassNullNaN = qqpassNum = false;
		var temp = false;
		var problemtype=false;
        var productWeight=true;
		$('.qco_quantity_problem').each(function(){
			var val = $(this).val(); var parseVal = parseInt(val);
			if(parseVal<0 || val=='' || isNaN(val) || val!=parseVal){ qqproblemNullNaN = true;}
			if(parseVal>parseInt($(this).attr('num'))){ qqproblemNum = true; }
			//如果未通过数大于实收数
			if(parseInt($("#qci_quantity_problem").val())>parseInt($("#qco_real_quantity").val())){ unqcnumMaxqco_real_quantity = true; }

			if(parseVal>0 && $('#ws_code'+$(this).attr('pid')).val()==''){ qqproblemCode = true;}

			//当实收与送检数不一至，要写<{$lang.remark}>
			if(parseInt($("#qci_quantity").html())!=parseInt($("#qco_real_quantity").val())){ qqNullNote = true; }

			if(parseVal>0 && $("#ptypeid_"+$(this).attr('textid')).val()==''){ problemtype = true; }

			if(parseVal>0 && $('#'+$(this).attr('textid')).val()==''){ temp = true; }
		});



		$('.qci_quantity_problem').each(function(){
			var total = 0; var maxNum = 0;
			$('.unpass'+$(this).attr('pid')).each(function(i,v){
				total += parseInt($(this).val());
				maxNum = parseInt($('.unpass'+$(this).attr('pid')+':eq(0)').val());
				if(maxNum < parseInt($('.unpass'+$(this).attr('pid')+':eq('+i+')').val())){
					maxNum =  parseInt($('.unpass'+$(this).attr('pid')+':eq('+i+')').val());
				}
			});
			var qval = $(this).val(); var parseQval = parseInt(qval);
			if(parseQval<maxNum || parseQval>total){ unpassCheck = true; }
			var qcr=$("#qco_real_quantity").val(); var qcrval=parseInt(qcr);
			if(qcrval<0 || qcr=='' || isNaN(qcr) || qcrval!=qcr){ qqpassNullNaNQR = true;}

			if(parseQval<0 || qval=='' || isNaN(qval) || parseQval!=qval){ qqpassNullNaN = true;}


			if(parseQval>parseInt($(this).attr('num'))){ qqpassNum = true; }

		});



		if(qqproblemNullNaN){
			$("#tipDialog").html('不合格<{$lang.quantity}>请正确填写,<br>应为非<{$lang.null}> 数字 且为自然数');
			$("#tipDialog").dialog("open");
			$("#qci_quantity_problem").focus();
			return false;
		}
		if(qqproblemNum){
			$("#tipDialog").html('不合格<{$lang.quantity}>不可大于送检<{$lang.quantity}>');
			$("#tipDialog").dialog("open");
			$("#qci_quantity_problem").focus();
			return false;
		}
		if(problemtype){
		    $("#tipDialog").html('当有不合格<{$lang.quantity}>时,应在其前面选问题<{$lang.type}>');
			$("#tipDialog").dialog("open");
			return false;
		}
		if(temp){
			$("#tipDialog").html('当有不合格<{$lang.quantity}>时,应在相应地方<{$lang.remark}>');
			$("#tipDialog").dialog("open");
			return false;
		}
		
		if(qqpassNullNaNQR){
			$("#tipDialog").html('实收总<{$lang.quantity}> 请正确填写,<br>应为非<{$lang.null}> 数字 且为自然数');
			$("#tipDialog").dialog("open");
			$("#qco_real_quantity").focus();
			return false;
		}
		
		if(unqcnumMaxqco_real_quantity){
		   $("#tipDialog").html('未通过QC<{$lang.quanlity}>总<{$lang.quantity}>不能大于实收<{$lang.quantity}>');
			$("#tipDialog").dialog("open");
			$("#qci_quantity_problem").focus();
			return false;
		}
		
		if(qqpassNullNaN){
			$("#tipDialog").html('未通过QC<{$lang.quanlity}>总<{$lang.quantity}>请正确填写,<br>应为非<{$lang.null}> 数字 且为自然数');
			$("#tipDialog").dialog("open");
			$("#qci_quantity_problem").focus();
			return false;
		}
		if(qqpassNum){
			$("#tipDialog").html('未通过QC<{$lang.quanlity}>总<{$lang.quantity}>不可大于送检<{$lang.quantity}>');
			$("#tipDialog").dialog("open");
			$("#qci_quantity_problem").focus();
			return false;
		}
		if(unpassCheck){
			$("#tipDialog").html('未通过QC<{$lang.quanlity}>总数,<br>量不可大于所有不合格数之和,<br>不可小于最大不合格数');
			$("#tipDialog").dialog("open");
			$("#qci_quantity_problem").focus();
			return false;
		}
		if(qqproblemCode){
			$("#tipDialog").html('当有不合格<{$lang.quantity}>时,应<{$lang.pls}>临时<{$lang.ws_code}>');
			$("#tipDialog").dialog("open");
			return false;
		}
		
		if(qqNullNote){
		    if($.trim($("#qco_note_order").val())==""){
			    $("#tipDialog").html('当送检<{$lang.quantity}>与实收<{$lang.quantity}>不一至时,要填写<{$lang.remark}>');
			    $("#tipDialog").dialog("open");
				$("#qco_note_order").focus();
			    return false;
			}
		   
		}
		
		$('.ws_code').each(function(){
			var tempVal = 0;
			$('[pid='+$(this).attr('wspid')+']').each(function(){
				tempVal+=parseInt($(this).val());
			});
			if(tempVal==0 && $(this).val()!=''){
			 	$("#tipDialog").html('都合格时,不应<{$lang.pls}><{$lang.ws_code}>应为<{$lang.null}>');
				$("#tipDialog").dialog("open");
				return false;
			}
		});

        if(productWeight){
            if($.trim($("#product_weight").val())==""){
                $("#tipDialog").html('请填写<{$lang.product}><{$lang.weight}>!');
                $("#tipDialog").dialog("open");
                $("#product_weight").focus();
                return false;
            }
        }
        if(valWeight()==false){
            tip='您<{$lang.input}>的<{$lang.product}><{$lang.weight}>与<{$lang.system}><{$lang.weight}>相差偏大，请<{$lang.confirm}>！';
            $('<div title="<{$lang.tip}>" id="alertTip" class="alertTip"><p align="center">' + tip + '</p></div>').dialog({
                modal:true,
                width:450,
                buttons:{
                    '<{$lang.ok}>':function () {
                        postqc();
                        $(this).dialog("close");
                    },
                    '<{$lang.cancel}>':function () {
                        $(this).dialog("close");
                    }
                }
            });
            return ;
        }

        postqc();
		/*$.post('/product/qc/qc-confirm',$('#qcConfrimForm').serialize(),function(data){
			if(data.ask==1){ 
				$("#tipDialog").html('Operation successful!');
				$("#tipDialog").dialog("open");
				window.location = '/product/qc/detail/code/'+$('[name=qco_code]').val() ;
			}else{
			    $("#tipDialog").html(data.msg);
				$("#tipDialog").dialog("open");
			}
		},'json');*/
		
	});
	
});
function postqc(){
    loading();
    $.ajax({
        type: "post",
        async: false,
        dataType: "json",
        url: "/product/qc/qc-confirm",
        data: $('#qcConfrimForm').serialize(),
        success: function(json) {
            closeLoading();
            if (json.ask==1) {
                $("#alertTip").dialog("close");
                $(".qcConfirm").hide();//防速度很慢重复<{$lang.submit}>
                $("#tipDialog").html('Operation successful!');
                $("#tipDialog").dialog("open");
                window.opener.changrow($('[name=qco_code]').val());
                location.reload();
               // window.location = '/product/qc/detail/code/'+$('[name=qco_code]').val() ;
                return true;

            }else{
                $("#tipDialog").html(json.msg);
                $("#tipDialog").dialog("open");
                return false;
            }
        }
    });
}
</script>
</head>
<body>
<div id='content'>
	<h1><{$lang.quanlity}><{$lang.msg}>录入</h1>
    <div class='qccontent'>
    	<form id='qcConfrimForm'>
        <table>
            <tr class="fontBold"><td><{$lang.quanlity_code}></td><td><{$lang.quanlity}>员</td><td>ASN NO.</td><td><{$lang.receive}>员</td><td><{$lang.receive}><{$lang.date}></td><td colspan=3><{$lang.quanlity}><{$lang.date}></td></tr>
            <tr><td><{$res.qco_code}><input name='qco_code' value='<{$res.qco_code}>' type='hidden'/><input name='qco_quantity' value='<{$res.qco_quantity}>' type='hidden'/></td>
                <td><{$res.qc_uname}></td>
                <td><{$res.qco_ref_code}><input name='qco_ref_code' value='<{$res.qco_ref_code}>' type='hidden'/></td>
                <td><{$res.reccvice_uname}></td>
                <td><{$res.recevice_date}></td>
                <td colspan=3><{$lang.system}><{$lang.time}></td></tr>
                
             <tr class="fontBold">
				<td><{$lang.product}><{$lang.picture}></td>
				<td><span style="color:#666; text-decoration:underline;"><{$lang.customer_code}></span><br><{$lang.product}><{$lang.sku}></td>
				<td>QC项目</td>
				<td>QC内容</td>
				<td colspan=1>不合格<{$lang.type}></td>
				<td colspan=2>不合格<{$lang.quantity}></td>
				<td colspan="2"><{$lang.remark}></td>
			</tr>
            <!---循环<{$lang.sku}>  循环<{$lang.sku}>中QC项目-->
            <{foreach from=$res.product_info item=items key=key}>
            	<input name='product_id[]' value='<{$key}>' type='hidden'/>
                <{foreach from=$items item=it key=k}>
                    <tr>
					<{if $k eq '0'}>
						<td rowspan='<{$items|@count+2}>'>
						
						 <{if $it.proAttId|@count neq 0}>
							 <{foreach from=$it.proAttId item=id key=kid}>
								<div class="product-img-view" style="<{if $kid neq '0'}>display:none;<{/if}>"><a class="fancybox-thumbs" data-fancybox-group="thumb" href="/product/product/view-qc-picture/paid/<{$id}>"><div style="width:75px;height:75px;"><img style="width:75px;height:75px;" src="/product/product/view-qc-picture/paid/<{$id}>"></div></a></div>
							 <{/foreach}>
						<{else}>
						<img style="width:75px;height:75px;" src="/product/product/view-qc-picture/paid/0">
						<{/if}>
						
						</td>
						<td rowspan='<{$items|@count+2}>'><span style="color:#666; text-decoration:underline;"><{$it.customer_id}></span><br><a href="/product/product/view-product-info/productId/<{$key}>" target="_blank"><{$it.product_sku}></a><br></td>                     <{/if}>
					<td><{$it.poc_value_cn}></td>
					<td><{$it.po_value}></td> 
					<td>
					   <label> 
							<select id="ptypeid_<{$key}><{$it.poc_id}>" name="qcr_problem_type[<{$key}>][<{$it.pov_id}>]">
								<option value=""><{$lang.pls}></option>
								<{foreach key=k item=item from=$problem_type}>
								<option value="<{$k}>"><{$item}></option>
								<{/foreach}>
							</select>
                       </label>&nbsp;
					</td>
					<td colspan=2>
					    <input size='2' style="text-align:center;" pid='<{$key}>' num='<{$it.qci_quantity}>' class='qco_quantity_problem unpass<{$key}>' textid='<{$key}><{$it.poc_id}>' name='qco_quantity_problem[<{$key}>][<{$it.pov_id}>]' value='0' />
					</td>
					<td><textarea id='<{$key}><{$it.poc_id}>' style='height:20px; text-align:left;' name='qco_note[<{$key}>][<{$it.pov_id}>]' ></textarea></td>
					<input type="hidden" id="<{$lang.sku}>" name="<{$lang.sku}>" value="<{$it.product_sku}>" />
					</tr>
                <{/foreach}>
                                
                <tr class="fontBold">
					<td><{$lang.product}><{$lang.weight}></td>
					<td>送检<{$lang.quantity}></td>
					<td>实收总<{$lang.quantity}></td>
					<td>未通过QC总数</td>
					<td>临时<{$lang.ws_code}></td>
					<td rowspan=2><textarea id='qco_note_order' style='height:40px; text-align:left;' name='qco_note_order' ></textarea></td>
				</tr>
                <tr>
					<td><input type="hidden" id='old_product_weight' value="<{$it.product_weight}>" name='old_product_weight'/><input style="text-align:center;" size=5  id='product_weight' value="" name='product_weight'/>KG</td>
					<td><span id="qci_quantity"><{$it.qci_quantity}></span></td>
					<td><input style="text-align:center;" size=9  id='qco_real_quantity' name='qco_real_quantity'/></td>
					<td><input style="text-align:center;" value="0" id="qci_quantity_problem" num='<{$it.qci_quantity}>' pid="<{$key}>" class='qci_quantity_problem' size='5' name='qci_quantity_problem[<{$key}>]' /></td>
					<td><input wspid='<{$key}>' size=5 style="text-align:right;" id='ws_code<{$key}>' class='ws_code' name='ws_code[<{$key}>]'/><a href="javascript:void(0);" onclick="qcSelectShelf(this,<{$key}>);"><img src="/images/icon/support.png" alt="<{$lang.pls}><{$lang.ws_code}>"></a>
					</td>
					
				</tr>
                
            <{/foreach}>
            <tr>
			<td><input type='button' value="STK<{$lang.detail}>" class='stkinfo button'> </td>
			<td colspan='7'>
			<input type="hidden" id="order_type" name="order_type" value="<{$res.order_type}>" />
			<input type="hidden" id="is_qc" name="is_qc" value="<{$res.is_qc}>" />
			<input type='button' value=' <{$lang.confirm}><{$lang.submit}> ' class='qcConfirm button'>
			</td>
			</tr>
        </table>
        </form>
    </div>
</div>
<div id="tipDialog" style="display:none" title="Tip"></div>

<!--<{$lang.pls}><{$lang.ws_code}>-->
<div id="shelfdialog" style="display:none;">
    <div style="padding: 10px; width: 92%;">
        <form id="shelfForm" name="shelfForm">
            <input type="hidden" id="select_product_id" name="select_product_id" value=""><!--用于对应判断对应<{$lang.directory}>-->
            <input type="hidden" name="s_wa_type" value="2">
            <div>
                <label>
                    <{$lang.warehouse}>：<select name="s_warehouse_id" id="warehouse_id" onchange="submitShelfSearch();"
                               class="text ui-widget-content">
                    <option value=""><{$lang.pls}></option>

                </select>
                </label>&nbsp;
                <label>
                    <{$lang.warehouse}><{$lang.zone}>：<select name="s_wa_code" onchange="submitShelfSearch();" id="room_wa_code"
                                 class="text ui-widget-content">
                    <option value=""><{$lang.pls}></option>
                </select>
                </label>&nbsp;
               <!-- <label>
                    房间号：<select name="s_wh_code" onchange="submitShelfSearch();" id="room_number"
                                class="text ui-widget-content">
                    <option value=""><{$lang.pls}></option>
                </select>
                </label>&nbsp;
				-->
                <input class="button searchshelf" type="button" value="<{$lang.search}>">
            </div>
        </form>
    </div>
    <div id="shelfloadData"></div>
    <div style="clear: both;"></div>
    <div class="pagination"></div>
</div>

</body>
</html>
